package coml.jiyun.hp.ershi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import coml.jiyun.hp.ershi.DbUtil;
import coml.jiyun.hp.ershi.R;
import coml.jiyun.hp.ershi.bean.WanBeanTwo;

public class RlvCollectAdapter extends RecyclerView.Adapter<RlvCollectAdapter.ViewHolder> {

    private Context context;
    private ArrayList<WanBeanTwo> wanBeanTwos;

    public RlvCollectAdapter(Context context, ArrayList<WanBeanTwo> wanBeanTwos) {
        this.context = context;
        this.wanBeanTwos = wanBeanTwos;
    }

    public void setWanBeanTwos(ArrayList<WanBeanTwo> wanBeanTwos) {
        this.wanBeanTwos = wanBeanTwos;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_collect, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.mTv_collect_tv.setText(wanBeanTwos.get(position).getTitle());


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClick.cx(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return wanBeanTwos.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView mItem_collect_img;
        TextView mTv_collect_tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            mItem_collect_img = itemView.findViewById(R.id.item_collect_img);
            mTv_collect_tv = itemView.findViewById(R.id.item_collect_tv);

        }
    }
//    List<WanBeanTwo> query = DbUtil.getDbUtil().query();
//            fuLiTwoBeans.addAll(query);
//            collectAdapter.setFuLiTwoBeans(fuLiTwoBeans);
//            collectAdapter.notifyDataSetChanged();

    public interface onItemClick{
        void cx(int i);
    }
    onItemClick onItemClick;

    public void setOnItemClick(RlvCollectAdapter.onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }
}
